package com.zsrd.self.controller;

import com.alibaba.fastjson.JSONObject;
import com.zsrd.self.base.Result;
import com.zsrd.self.entity.vo.GenerateschemeVo;
import com.zsrd.self.handle.WChatHandle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <pre>
 *
 * </pre>
 *
 * @author sunjiyong
 * @since 2024/3/4 11:35
 */

@RequestMapping("/wchat/api")
@RestController
@CrossOrigin(origins = "*")
public class WchatController {

    @Autowired
    private WChatHandle wchatHandle;

    @PostMapping("/generatescheme")
    public Result generatescheme(@RequestBody GenerateschemeVo param){
        JSONObject jumpWx = new JSONObject();
        jumpWx.put("path",param.getPath());
        jumpWx.put("query",param.getQuery());
        String scheme = wchatHandle.generateScheme(JSONObject.toJSONString(jumpWx));
        return Result.success(scheme);
    }

    @PostMapping("/getOpenId")
    public Result getOpenId(@RequestBody GenerateschemeVo param){
        String data = wchatHandle.getOpenId(param.getCode());
        return Result.success(data);
    }

}
